package com.kasax.httpclient;

import android.text.TextUtils;

import java.net.MalformedURLException;
import java.net.URL;

public class HttpUrl {
    // 主机地址
    String host;
    // 协议
    String protocol;
    // 文件地址
    String file;
    // 端口
    int port;

    public HttpUrl(String url) throws MalformedURLException {
        URL urlObj = new URL(url);
        protocol = urlObj.getProtocol();
        host = urlObj.getHost();
        file = urlObj.getFile();
        file = TextUtils.isEmpty(file) ? "/" : file;
        port = urlObj.getPort();
        port = port == -1 ? urlObj.getDefaultPort() : port;
    }

    public String getHost() {
        return host;
    }

    public String getProtocol() {
        return protocol;
    }

    public String getFile() {
        return file;
    }

    public int getPort() {
        return port;
    }
}
